/*
 * Copyright (c) 2020, 2023, 3044483124@qq.com All rights reserved.
 *
 */
package cn.itcast;

import java.util.*;

/**
 * <p>Project: JavaStudy - Work2
 * <p>Powered by jiangbo On 2023-01-12
 * 14:35:14
 * <p>Created by IntelliJ IDEA
 *
 * @author jiangbo [3044483124@qq.com]
 * @version 1.0
 * @since 8/17
 */
public class Work2 {
    public static void main(String[] args) {
        String[] s = {"ate","att","test","ttes","tae"};
        System.out.println(new Work2().stringGroup(s));
    }
    public List<List<String>> stringGroup(String[] strs){
        if(strs == null || strs.length == 0){
            return new ArrayList<>();
        }
        Arrays.sort(strs);
        Map<String,List<String>> map = new HashMap<>();
        for(String str : strs){
            char[] c = str.toCharArray();
            Arrays.sort(c);
            String sortedStr = String.valueOf(c);
            if(!map.containsKey(sortedStr))
                map.put(sortedStr,new ArrayList<>());
            map.get(sortedStr).add(str);
        }
        return new ArrayList<>(map.values());
    }
}


